import { http } from "../http";
import {
  mockGetContactList,
  mockAddOrUpdateContact,
  mockDeleteContact,
  mockGetContactById,
} from "../mock/contact";

const baseUrl = "/api/dms/vendorContacts";

// 控制是否使用Mock API的全局变量
const USE_MOCK = false; // 设置为 true 使用Mock，false 使用真实API

export interface ContactType {
  id: string;
  companyName: string;
  contactName: string;
  contactPhone: string;
  deviceId: string;
}

export interface AddOrUpdateContactQueryType {
  id?: string | null;
  companyName: string | null;
  contactName: string | null;
  contactPhone: string | null;
  deviceId: string | null;
}

// 添加或编辑联系人
export const addVendorContactAPI = (params: AddOrUpdateContactQueryType) => {
  if (USE_MOCK) {
    return mockAddOrUpdateContact(params).then((data) => data.data);
  }
  return http.post(`${baseUrl}/addOrUpdateVendorContact`, params);
};

// 删除联系人
export const deleteVendorContactAPI = (id: string) => {
  if (USE_MOCK) {
    return mockDeleteContact(id).then((data) => data.data);
  }
  return http.delete(`${baseUrl}/deleteVendorContact/${id}`);
};

// 根据ID获取联系人详情
export const getVendorContactsByDeviceIdAPI = (id: string) => {
  if (USE_MOCK) {
    return mockGetContactById(id).then((data) => data.data);
  }
  return http.get(`${baseUrl}/getVendorContactsByDeviceId/${id}`);
};
